package br.unesp.rc.locadora.beans;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.ManyToMany;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import java.util.Date;
import java.util.List;

@Entity
@Table(name="Locacao")
public class Locacao{
	
	private long idLocacao;
	private Date dataHoraRetirada;
	private Date dataHoraDevolucao;
	private Pessoa pessoa;
	private List<Servico> servico;
	private List<Carro> carros;
	private Fatura fatura;
	
	@Id
	@GeneratedValue
	@Column(name="idLocacao")
	public long getIdLocacao(){
		return idLocacao;
	}
	
	public void setIdLocacao(long idLocacao){
		this.idLocacao = idLocacao;
	}
	
	@Column(name="dataHoraRetirada")
	@Temporal(javax.persistence.TemporalType.DATE)
	public Date getDataHoraRetirada(){
		return dataHoraRetirada;
	}
	
	public void setDataHoraRetirada(Date dataHoraRetirada){
		this.dataHoraRetirada = dataHoraRetirada;
	}
	
	@Column(name="dataHoraDevolucao")
	@Temporal(javax.persistence.TemporalType.DATE)
	public Date getDataHoraDevolucao(){
		return dataHoraDevolucao;
	}
	
	public void setDataHoraDevolucao(Date dataHoraDevolucao){
		this.dataHoraDevolucao = dataHoraDevolucao;
	}
	
	public Pessoa getPessoa(){
		return pessoa;
	}
	
	public void setPessoa(Pessoa pessoa){
		this.pessoa = pessoa;
	}
	
	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name="LocacaoServico",joinColumns={@JoinColumn(name="locacao")},inverseJoinColumns={@JoinColumn(name="servico")})
	public List<Servico> getServico(){
		return servico;
	}
	
	public void setServico(List<Servico> servico){
		this.servico = servico;
	}
	
	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name="LocacaoCarro",joinColumns={@JoinColumn(name="locacao")},inverseJoinColumns={@JoinColumn(name="carros")})
	public List<Carro> getCarros(){
		return carros;
	}
	
	public void setCarros(List<Carro> carros){
		this.carros = carros;
	}
	
	@OneToOne(mappedBy="locacao",cascade=CascadeType.ALL)
	public Fatura getFatura(){
		return fatura;
	}
	
	public void setFatura(Fatura fatura){
		this.fatura = fatura;
	}
	
}
